import 'dart:async';
import 'dart:convert';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/dialog/info_dialog.dart';
import 'package:wallet_utils/event_bus_utils.dart';
import 'package:wallet_utils/location/locationUtil.dart';
import 'package:wallet_utils/log_util.dart';
import 'package:wallet_utils/msg_event_utils.dart';
import 'package:wallet_utils/report_widget/base/callback/base_callback.dart';
import 'package:wallet_utils/report_widget/loading_utils.dart';
import 'package:wallet_utils/toast.dart';
import '../../login_page/constant.dart';
import '../../mine/api/mine_api.dart';
import '../../mine/bean/aboutUsBean.dart';
import '../../mine/contentType.dart';
import '../api/home_api.dart';
import '../bean/basicInfoBean.dart';
import '../bean/basicInfoConfirm.dart';
import '../bean/controlBean.dart';
import '../bean/controlEntryBean.dart';
import '../bean/offlineOrganizationBean.dart';
import '../bean/popUpsBean.dart';
import '../bean/userAgreementBean.dart';
import '../bean/userInfoBean.dart';
import 'state.dart';
import 'dart:convert' as convert;

class BasicInfoLogic extends GetxController {
  final BasicInfoState state = BasicInfoState();
  num? face;
  num? isShowIdCard;
  bool showContacts = false;
  num? channelAuthType;
  BasicInfoBean? basicBean;
  DataInfo? userInfo;
  ControlEntry? dataInfo;
  AnimationController? animationController;
  Product? product;
  OfflineProduct? offlineProduct;
  List<PopUpsInfo> popUpsInfo = [];

  @override
  void onInit() {
    super.onInit();
    if (Get.arguments != null) {
      face = Get.arguments['face'];
      showContacts = Get.arguments['showContacts'];
      isShowIdCard = Get.arguments['isShowIdCard'];
      channelAuthType = Get.arguments['channelAuthType'];
    }
    // getUser2WhereApi();
    getUserInfo(ContentType.personalCredit);
    LocationUtil().request(
        onResult: (Map<String, Object> result) async {
          LogUtils.d("-------------直接取");
          LogUtils.d(result);
          state.city = result['city'].toString();
          state.province = result['province'].toString();
          state.address = result['address'].toString();
          state.longitude = result['longitude'].toString();
          state.latitude = result['latitude'].toString();
          update();
          LogUtils.d('城市 ${state.city}');
        },
        isResetLocation: false);
    if (isShowIdCard == 0) {
      state.proState = false;
    } else {
      if (channelAuthType == 2) {
        state.proState = false;
      } else {
        state.proState = true;
        if (face == 1 && showContacts) {
          state.proText = '30%';
          state.percent = 84;
        } else {
          state.proText = '50%';
          state.percent = 140;
        }
        update();
      }
    }

    rootBundle.loadString('assets/authInfo.json').then((address) {
      var data = json.decode(address);
      basicBean = BasicInfoBean.fromJson(data);
    });
    channelIncomingControl();
    getCpaPopList();
  }

  //弹窗
  void getCpaPopList() async {
    HomeApi.getCpaPopList(
        PopUps().input,
        BaseCallback(onSuccess: (map) {
          PopUpsBean popUpsBean = PopUpsBean.fromJson(map);
          popUpsInfo = popUpsBean.data!;
          if (popUpsInfo.isNotEmpty) {
            state.amount = popUpsInfo[0].amount;
            state.name = popUpsInfo[0].name;
            state.popLinkUrl = popUpsInfo[0].linkUrl;
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            ToastUtils.showToast(msg ?? "");
          });
        }));
  }

  //件信息详情信息接口（后置）
  Future<bool?> incomingDetailV2() async {
    bool? flag = false;
    await HomeApi.incomingDetailV2(
        state.detailBean,
        BaseCallback(onSuccess: (map) {
          Future.delayed(const Duration(milliseconds: 1000), () {
            getUser2WhereApi();
          });
          BasicInfoConfirm basicInfoConfirm = BasicInfoConfirm.fromJson(map);
          if (basicInfoConfirm.data?.product != null) {
            flag = true;
            product = basicInfoConfirm.data?.product;
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            Get.back();
            ToastUtils.showToast(msg ?? "");
          });
        }));
    return flag;
  }

  //件信息详情信息接口（前置）
  Future<bool?> incomingDetail() async {
    bool? flag = false;
    await HomeApi.incomingDetail(
        state.detailBean,
        BaseCallback(onSuccess: (map) async {
          Future.delayed(const Duration(milliseconds: 1000), () {
            getUser2WhereApi();
          });
          OfflineOrganizationBean offlineOrganizationBean = OfflineOrganizationBean.fromJson(map);

          if (offlineOrganizationBean.data?.basicV3ResultVO?.product != null) {
            flag = true;
            offlineProduct = offlineOrganizationBean.data?.basicV3ResultVO?.product;
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            Get.back();
            ToastUtils.showToast(msg ?? "");
          });
        }));
    return flag;
  }

  Future<bool?> submit() async {
    bool? flag = false;
    if (state.controlList.isEmpty) {
      ToastUtils.showToast('请填写基本信息');
    } else {
      if (dataInfo?.isShowName == 1) {
        state.detailBean!.name = state.nameController.text;
      }
      if (dataInfo?.isShowIdCard == 1) {
        state.detailBean!.idCard = state.idCardController.text;
      }
      if (dataInfo?.isShowAge == 1) {
        state.detailBean!.age = state.ageController.text;
      }
      if (dataInfo?.isShowMonthIncome == 1) {
        state.detailBean!.monthIncome = state.monthIncomeController.text;
      }
      if (dataInfo?.isShowName == 1 && state.detailBean!.name!.isEmpty) {
        ToastUtils.showToast('请输入您的真实姓名');
      } else if (dataInfo?.isShowIdCard == 1 && state.detailBean!.idCard!.isEmpty) {
        ToastUtils.showToast('请输入您的身份证号');
      } else if (dataInfo?.isShowAge == 1 && state.detailBean!.age!.isEmpty) {
        ToastUtils.showToast('请输入您的年龄');
      } else if (dataInfo?.isShowMonthIncome == 1 && state.detailBean!.monthIncome!.isEmpty) {
        ToastUtils.showToast('请输入您的月输入');
      }else if (dataInfo?.isShowLoanMount == 1 && state.detailBean!.loanAmount!.isEmpty) {
        ToastUtils.showToast('请选择借多少');
      } else if (dataInfo?.isShowLoanTime == 1 && state.detailBean!.loanPeriod!.isEmpty) {
        ToastUtils.showToast('请选择借多久');
      } else if (dataInfo?.isShowLoanPurpose == 1 && state.detailBean!.loanPurpose!.isEmpty) {
        ToastUtils.showToast('请选择借款用途');
      } else if (dataInfo?.isShowEducation == 1 && state.detailBean!.education!.isEmpty) {
        ToastUtils.showToast('请选择教育程度');
      }else if (dataInfo?.isShowHouseType == 1 && state.detailBean!.houseType!.isEmpty) {
        ToastUtils.showToast('请选择房产类型');
      } else if (dataInfo?.isShowMarry == 1 && state.detailBean!.marriage!.isEmpty) {
        ToastUtils.showToast('请选择婚姻状况');
      } else if (dataInfo?.hasShowAssetsFields == 1 && state.detailBean!.propertyItems.isEmpty) {
        ToastUtils.showToast('请选择资产信息');
      }  else if (dataInfo?.hasShowAuthFields == 1 && state.detailBean!.credit!.isEmpty) {
        ToastUtils.showToast('请选择芝麻分');
      } else if (dataInfo?.hasShowJdIousFields == 1 && state.detailBean!.jddept!.isEmpty) {
        ToastUtils.showToast('请选择京东白条');
      } else if (state.province!.isEmpty) {
        ToastUtils.showToast('请选择城市');
      } else {
        Map<String, dynamic> paramsMap = {
          "province": state.province,
          "city": state.city,
        "longitude": state.longitude,
        "latitude": state.latitude,
        };
        if (state.detailBean!.propertyItems.endsWith(',')) {
          state.detailBean!.propertyItems =
              state.detailBean!.propertyItems.substring(0, (state.detailBean!.propertyItems).length - 1);
        }
        state.detailBean?.locationGps = convert.jsonEncode(paramsMap);
        state.detailBean?.gpsCityName = state.city;
        state.detailBean?.step = 1;
        LoadingUtils.showLoading(Get.context!, isCanBack: false);
        if (isShowIdCard == 0) {
          flag = await incomingDetail();
        } else {
          if (channelAuthType == 1) {
            flag = await incomingDetail();
          } else {
            flag = await incomingDetailV2();
            LogUtils.d('状态   $flag');
          }
        }
        // LogUtils.d('json   ${state.detailBean?.toJson()}');

      }
    }
    return flag;
  }

  String? listToString(List<String> list) {
    if (list.isEmpty) {
      return null;
    }
    String? result;
    list.forEach((string) => {if (result == null) result = string else result = '$result,$string'});
    return result.toString();
  }

  //进件控制页
  void channelIncomingControl() async {
    HomeApi.channelIncomingControl(BaseCallback(onSuccess: (map) {
      ControlEntryBean controlEntryBean = ControlEntryBean.fromJson(map);
      if (controlEntryBean.data != null) {
        dataInfo = controlEntryBean.data;
        //姓名
        if (dataInfo?.isShowName == 1) {
          state.isShowName = true;
        }
        //身份证号
        if (dataInfo?.isShowIdCard == 1) {
          state.isShowIdCard = true;
        }
        //年龄
        if (dataInfo?.isShowAge == 1) {
          state.isShowAge = true;
        }
        //月收入
        if (dataInfo?.isShowMonthIncome == 1) {
          state.isShowMonthIncome = true;
        }
        //借多多
        if (dataInfo?.isShowLoanMount == 1) {
          IsShowLoanMount? loanMount = basicBean?.data?.isShowLoanMount;
          loanMount?.mountContent?.forEach((element) {
            state.childData.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(loanMount?.title, state.childData, 0));
        }
        //借多久
        if (dataInfo?.isShowLoanTime == 1) {
          IsShowLoanTime? loanTime = basicBean?.data?.isShowLoanTime;
          loanTime?.timeContent?.forEach((element) {
            state.loanTimeList.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(loanTime?.title, state.loanTimeList, 0));
        }
        //借款用途
        if (dataInfo?.isShowLoanPurpose == 1) {
          IsShowLoanPurpose? purpose = basicBean?.data?.isShowLoanPurpose;
          purpose?.purposeContent?.forEach((element) {
            state.purposeList.add(ChildData(
              element.text,
              false,
            ));
          });
          state.controlList.add(ControlBean(purpose?.title, state.purposeList, 0));
        }
        //住房类型
        if (dataInfo?.isShowHouseType == 1) {
          IsShowHouseType? houseType = basicBean?.data?.isShowHouseType;
          houseType?.houseContent?.forEach((element) {
            state.houseList.add(ChildData(
              element.text,
              false,
            ));
          });
          state.controlList.add(ControlBean(houseType?.title, state.houseList, 0));
        }
        //教育程度
        if (dataInfo?.isShowEducation == 1) {
          IsShowEducation? education = basicBean?.data?.isShowEducation;
          education?.eduContent?.forEach((element) {
            state.educationList.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(education?.title, state.educationList, 0));
        }
        //婚姻
        if (dataInfo?.isShowMarry == 1) {
          IsShowMarry? marry = basicBean?.data?.isShowMarry;
          marry?.marryContent?.forEach((element) {
            state.marryList.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(marry?.title, state.marryList, 0));
        }
        //资产信息
        if (dataInfo?.hasShowAssetsFields == 1) {
          HasShowAssetsFields? assetsFields = basicBean?.data?.hasShowAssetsFields;
          assetsFields?.assetsContent?.forEach((element) {
            state.assetsFields.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(assetsFields?.title, state.assetsFields, 1));
        }
        //芝麻分
        if (dataInfo?.hasShowAuthFields == 1) {
          HasShowAuthFields? authFields = basicBean?.data?.hasShowAuthFields;
          authFields?.authContent?.forEach((element) {
            state.authFields.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(authFields?.title, state.authFields, 0));
        }
        //京东白条
        if (dataInfo?.hasShowJdIousFields == 1) {
          HasShowJdIousFields? iouFields = basicBean?.data?.hasShowJdIousFields;
          iouFields?.iouContent?.forEach((element) {
            state.iouFields.add(ChildData(element.text, false));
          });
          state.controlList.add(ControlBean(iouFields?.title, state.iouFields, 0));
        }
        LogUtils.d('集合内容 ${state.controlList.toString()}');
        getAppUserInfoAll();
        update();
      }
    }, onError: (msg) {
      Future.delayed(const Duration(milliseconds: 500), () {
        ToastUtils.showToast(msg ?? "");
      });
    }));
  }

  //查询用户及进件所有信息
  void getAppUserInfoAll() async {
    HomeApi.getAppUserInfoAll(BaseCallback(onSuccess: (map) {
      UserInfoBean userInfoBean = UserInfoBean.fromJson(map);
      if (userInfoBean.data != null) {
        userInfo = userInfoBean.data;
        if (userInfo?.userInfo?.userName != null) {
          state.nameController.text = userInfo?.userInfo?.userName;
          state.detailBean?.name = userInfo?.userInfo?.userName;
        }
        if (userInfo?.userInfo?.idCard != null) {
          state.idCardController.text = userInfo?.userInfo?.idCard;
          state.detailBean?.idCard = userInfo?.userInfo?.idCard;
        }
        if (userInfo?.userInfo?.age != null && userInfo?.userInfo?.age != 0) {
          state.ageController.text = userInfo!.userInfo!.age!.toString();
          state.detailBean?.age = userInfo!.userInfo!.age!.toString();
        }
        if (userInfo?.userInfo?.monthIncome != null && userInfo?.userInfo?.monthIncome != 0) {
          state.monthIncomeController.text = userInfo!.userInfo!.monthIncome!.toString();
          state.detailBean?.monthIncome = userInfo!.userInfo!.monthIncome!.toString();
        }
        if (userInfo?.userInfo?.userName != null) {
          state.nameController.text = userInfo?.userInfo?.userName;
        }
        if (userInfo?.userDetail?.loanAmount != null) {
          state.childData.forEach((element) {
            if (userInfo?.userDetail?.loanAmount == element.name) {
              element.isSelect = true;
              state.detailBean?.loanAmount = element.name;
            }
          });
        }
        //借款用途
        if (userInfo?.userDetail?.loanPurpose != null) {
          state.purposeList.forEach((element) {
            if (userInfo?.userDetail?.loanPurpose == element.name) {
              element.isSelect = true;
              state.detailBean?.loanPurpose = element.name;
            }
          });
        }
        //借多久
        if (userInfo?.userDetail?.loanPeriod != null) {
          state.loanTimeList.forEach((element) {
            if (userInfo?.userDetail?.loanPeriod.toString() == element.name) {
              element.isSelect = true;
              state.detailBean?.loanPeriod = element.name;
            }
          });
        }
        //教育
        if (userInfo?.userDetail?.education != null) {
          state.educationList.forEach((element) {
            if (userInfo?.userDetail?.education == element.name) {
              element.isSelect = true;
              state.detailBean?.education = element.name;
            }
          });
        }
        //婚姻
        if (userInfo?.userDetail?.marriage != null) {
          state.marryList.forEach((element) {
            if (userInfo?.userDetail?.marriage == element.name) {
              element.isSelect = true;
              state.detailBean?.marriage = element.name;
            }
          });
        }
        //芝麻分
        if (userInfo?.userDetail?.credit != null) {
          state.authFields.forEach((element) {
            if (userInfo?.userDetail?.credit == element.name) {
              element.isSelect = true;
              state.detailBean?.credit = element.name;
            }
          });
        }
        //京东白条
        if (userInfo?.userDetail?.jdIousLevel != null) {
          state.iouFields.forEach((element) {
            if (element.name == '无') {
              if (userInfo?.userDetail?.jdIousLevel == 0) {
                element.isSelect = true;
                state.detailBean?.jddept = '0';
              }
            }
            if (element.name == "5000以下") {
              if (userInfo?.userDetail?.jdIousLevel == 1) {
                element.isSelect = true;
                state.detailBean?.jddept = '1';
              }
            }
            if (element.name == "5000以上") {
              if (userInfo?.userDetail?.jdIousLevel == 2) {
                element.isSelect = true;
                state.detailBean?.jddept = '2';
              }
            }
          });
        }
        //资产
        if (userInfo?.propertyItems != null) {
          state.assetsFields.forEach((element) {
            if (userInfo!.propertyItems!.contains(element.name ?? '')) {
              element.isSelect = true;
              if (state.detailBean!.propertyItems.isEmpty) {
                state.detailBean?.propertyItems += element.name!;
              } else {
                state.detailBean?.propertyItems += ',' + element.name!;
              }
            }
          });
        }
        //住房类型
        if (userInfo?.userDetail?.houseType != null) {
          state.houseList.forEach((element) {
            if (userInfo?.userDetail?.houseType == element.name) {
              element.isSelect = true;
              state.detailBean?.houseType = element.name;
            }

            // 3:全款/2:按揭/4:租房/6:宿舍/5:自建房/7:父母同住/1:其他
            if (element.name == '其他') {
              if (userInfo?.userDetail?.houseType == 1) {
                element.isSelect = true;
                state.detailBean?.houseType = '1';
              }
            }
            if (element.name == '按揭') {
              if (userInfo?.userDetail?.houseType == 2) {
                element.isSelect = true;
                state.detailBean?.houseType = '2';
              }
            }
            if (element.name == '全款') {
              if (userInfo?.userDetail?.houseType == 3) {
                element.isSelect = true;
                state.detailBean?.houseType = '3';
              }
            }
            if (element.name == '租房') {
              if (userInfo?.userDetail?.houseType == 4) {
                element.isSelect = true;
                state.detailBean?.houseType = '4';
              }
            }
            if (element.name == '自建房') {
              if (userInfo?.userDetail?.houseType == 5) {
                element.isSelect = true;
                state.detailBean?.houseType = '5';
              }
            }
            if (element.name == '宿舍') {
              if (userInfo?.userDetail?.houseType == 6) {
                element.isSelect = true;
                state.detailBean?.houseType = '6';
              }
            }
            if (element.name == '父母同住') {
              if (userInfo?.userDetail?.houseType == 7) {
                element.isSelect = true;
                state.detailBean?.houseType = '7';
              }
            }
          });
        }

        update();
      }
    }, onError: (msg) {
      Future.delayed(const Duration(milliseconds: 500), () {
        ToastUtils.showToast(msg ?? "");
      });
    }));
  }

  void isCheckStatus(position, index) {
    for (int i = 0; i < state.controlList.length; i++) {
      if (index == i) {
        if (state.controlList[i].type == 0) {
          for (int j = 0; j < state.controlList[i].childData!.length; j++) {
            if (position == j) {
              state.controlList[i].childData![j].isSelect = true;
              var name = state.controlList[i].childData![j].name;
              if (state.controlList[i].title == '借多少(元)') {
                state.detailBean?.loanAmount = name;
              }
              if (state.controlList[i].title == '借多久(月)') {
                state.detailBean?.loanPeriod = name;
              }
              if (state.controlList[i].title == '借款用途') {
                state.detailBean?.loanPurpose = name;
              }
              if (state.controlList[i].title == '芝麻分(单选)') {
                state.detailBean?.credit = name;
              }
              if (state.controlList[i].title == '京东白条(单选)') {
                if (name == '无') {
                  state.detailBean?.jddept = '0';
                } else if (name == '5000以下') {
                  state.detailBean?.jddept = '1';
                } else {
                  state.detailBean?.jddept = '2';
                }
              }
              if (state.controlList[i].title == '教育程度(单选)') {
                state.detailBean?.education = name;
              }
              if (state.controlList[i].title == '婚姻状况(单选)') {
                state.detailBean?.marriage = name;
              }
              if (state.controlList[i].title == '房产类型(单选)') {
                // 3:全款/2:按揭/4:租房/6:宿舍/5:自建房/7:父母同住/1:其他
                if (name == '其他') {
                  state.detailBean?.houseType = '1';
                } else if (name == '按揭') {
                  state.detailBean?.houseType = '2';
                } else if (name == '全款') {
                  state.detailBean?.houseType = '3';
                } else if (name == '租房') {
                  state.detailBean?.houseType = '4';
                } else if (name == '自建房') {
                  state.detailBean?.houseType = '5';
                } else if (name == '宿舍') {
                  state.detailBean?.houseType = '6';
                } else if (name == '父母同住') {
                  state.detailBean?.houseType = '7';
                }
              }

            } else {
              state.controlList[i].childData![j].isSelect = false;
            }
          }
        } else {
          for (int j = 0; j < state.controlList[i].childData!.length; j++) {
            if (position == j) {
              var name = state.controlList[i].childData![j].name;
              if (state.controlList[i].childData![j].isSelect) {
                state.controlList[i].childData![j].isSelect = false;
                List<String>? arrayNew = state.detailBean?.propertyItems.split(',');
                if (arrayNew!.isNotEmpty) {
                  for (int i = 0; i < arrayNew.length; i++) {
                    if (arrayNew[i] == name) {
                      arrayNew.remove(name);
                    }
                  }
                  // arrayNew.removeAt(arrayNew.length-1);
                  state.detailBean?.propertyItems = listToString(arrayNew)!;
                }
              } else {
                state.controlList[i].childData![j].isSelect = true;
                if (state.controlList[i].title == '资产信息(多选)') {
                  if (state.detailBean!.propertyItems.isEmpty) {
                    state.detailBean?.propertyItems += name!;
                  } else {
                    state.detailBean?.propertyItems += ',' + name!;
                  }
                }
              }
            }
          }
        }
      }
    }
    update();
  }

  Future<void> jumpFace() async {
    WidgetsFlutterBinding.ensureInitialized();
    state.cameras = await availableCameras();

    /// 获取设备摄像头，默认0:后置 1:前置
    state.firstCamera = state.cameras!.first;
    Get.toNamed(BaseRouterConfig.faceRecognition, arguments: {
      'isShowIncoming':false,
      'camera': state.cameras,
    });
  }

  void backPage() {
    if (channelAuthType == 1) {
      EventBusUtils.getInstance().fire(MsgEventBusUtils(MsgEventBusUtils.upHomeStatus, value: false));
      Get.until((route) => (route.settings.name == BaseRouterConfig.main));
    } else {
      Get.back();
    }
  }

  //信用授权书
  getUserInfo(int type) {
    MineApi.getHTML(
        type,
        BaseCallback(onSuccess: (map) {
          AboutUsBean aboutUsBean = AboutUsBean.fromJson(map);
          if (aboutUsBean.data != null) {
            state.agreementName = aboutUsBean.data?.name;
            state.content = aboutUsBean.data?.content;
            // Get.toNamed(BaseRouterConfig.agreement, arguments: {'name': state.agreementName, 'content': state.agreementContent});
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            ToastUtils.showToast(msg ?? "");
          });
        }));
  }

  jumpPage() async {
    if (isShowIdCard == 0) {
      await preposition();
    } else {
      if (channelAuthType == 2) {
        Get.toNamed(BaseRouterConfig.identityCertification, arguments: {
          'isShowIncoming': false,
          'face': face,
          'showContacts': showContacts,
          'channelAuthType': channelAuthType,
        });
      } else {
        await preposition();
      }
    }
  }

  Future<void> preposition() async {
    if (showContacts) {
      Get.toNamed(BaseRouterConfig.contactPerson, arguments: {
        'isShowIncoming': false,
        'face': face,
        'isShowIdCard': isShowIdCard,
        'channelAuthType': channelAuthType,
      });
    } else if (face == 1 && !showContacts) {
      await jumpFace();
    } else if (face == 0 && !showContacts) {
      Get.toNamed(BaseRouterConfig.auditRejection);
    }
  }

  bool isStatus() {
    bool flag = false;
    if (isShowIdCard == 0) {
      flag = true;
    } else {
      if (channelAuthType == 1) {
        flag = true;
      } else {
        flag = false;
      }
    }
    return flag;
  }

  bool isEditContent() {
    bool flag = false;
    if (isShowIdCard == 0) {
      flag = true;
    } else {
      if (channelAuthType == 1) {
        flag = false;
      } else {
        flag = true;
      }
    }
    return flag;
  }

  void startCountdownTimer() {
    const oneSec = Duration(seconds: 1);
    // ignore: prefer_function_declarations_over_variables
    var callback = (timer) {
      if (state.countdownTime < 1) {
        Get.back();
        state.timer.cancel();
        // jumpPage();
      } else {
        state.countdownTime = state.countdownTime - 1;
      }
      update();
    };

    state.timer = Timer.periodic(oneSec, callback);
  }

  void getUser2WhereApi() async {
    HomeApi.getUser2WhereApi(BaseCallback(onSuccess: (map) {
      UserAgreementBean userAgreementBean = UserAgreementBean.fromJson(map);
      Get.back();
      if (userAgreementBean.data != null) {
        state.agreementContent = userAgreementBean.data?.content;
        if (userAgreementBean.data!.companyName!.isNotEmpty) {
          Get.toNamed(BaseRouterConfig.offlineProduct, arguments: {
            'productInfo': userAgreementBean.data,
            'face': face,
            'showContacts': showContacts,
            'isShowIdCard': isShowIdCard,
            'channelAuthType': channelAuthType
          });
        } else {
          jumpPage();
        }
      }
    }, onError: (msg) {
      Future.delayed(const Duration(milliseconds: 500), () {
        Get.back();
        ToastUtils.showToast(msg ?? "");
      });
    }));
  }

  @override
  void onClose() {
    LocationUtil().destroyLocation();
    super.onClose();
  }
}
